<template>
  <el-dialog title="订单详情" :close-on-click-modal="false" :visible.sync="visible" width="50%">
    <el-form :model="dataForm" ref="dataForm" label-width="100px">
      <el-row>
        <el-col :span="11">
          <el-form-item label="用户id" prop="userId">
            <el-input readonly v-model="dataForm.userId" placeholder="用户id"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="商品名称" prop="productId">
            <el-input readonly v-model="dataForm.productName" placeholder="商品名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="商品单价" prop="productId">
            <el-input readonly v-model="dataForm.productPrice" placeholder="商品单价"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="购买数量" prop="productNum">
            <el-input readonly v-model="dataForm.productNum" placeholder="购买商品数量"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="支付金额" prop="payAmount">
            <el-input readonly v-model="dataForm.payAmount" placeholder="支付金额"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="创建时间" prop="createTime">
            <el-input readonly v-model="dataForm.createTime" placeholder="创建时间"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="支付时间" prop="payTime">
            <el-input readonly v-model="dataForm.payTime" placeholder="支付时间"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="支付状态" prop="status">
            <el-input readonly v-model="statusChange" placeholder="支付状态">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="11">
          <el-form-item label="支付失败原因" prop="">
            <el-input readonly v-model="reasonChange" placeholder="支付失败原因"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-button type="primary" @click="visible = false">关闭</el-button>
  </el-dialog>
</template>

<script>
import request from "@/utils/request";

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        userId: '',
        productName: '',
        productPrice: '',
        productNum: '',
        payAmount: '',
        createTime: '',
        status: '',
        payTime: '',
        payResoult: ''
      },
      statusMap: {
        '0': '待支付',
        '1': '已支付',
        '2': '支付失败'
      },
      reasonMap: {
        '0': '取消支付',
        '1': '库存不足',
        '2': '支付逾期'
      }

    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          request.get(`/order/admin/info/${this.dataForm.id}`, {}).then((response) => {
            if (response.data && response.data.code === 200) {
              this.dataForm = response.data.order
              if (this.dataForm.payTime === null) {
                this.dataForm.payTime = '空'
              }
            }
          })
        }
      })
    },
  },

  computed: {
    //展示实际状态
    statusChange() {
      return this.statusMap[this.dataForm.status] || '空'
    },
    //展示实际原因
    reasonChange() {
      return this.reasonMap[this.dataForm.payResoult] || '空'
    }
  }
}
</script>
